import React, { Component } from 'react'
import PropTypes from 'prop-types';
export default class header extends Component {


static propTypes={
  addTodo:PropTypes.func.isRequired
}

  inputChange = (event) => {
    const {addTodo}=this.props
    const { target, keyCode } = event
    if (target.value.trim() === '') {
      alert("待办事项不能为空")
      return
    }
    if (keyCode !== 13) return
    let todoObj={
      id:Math.floor(Math.random()*100),
      name:target.value,
      done:false
    }
    addTodo(todoObj)
    target.value=""
  }
  render() {
    return (
      <div>
        <input onKeyUp={this.inputChange} type="text" placeholder="请输入待完成的事" />
      </div>
    )
  }
}
